BaseAscii      PROTO :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD

Num            dd  0
szBuff         db  20 dup(?)

;==========================================================================
; Converts a 32 bit num value to a Dec, Hex, Oct or Bin ascii string.    *
;==========================================================================
;INVOKE     BaseAscii, Num, addr szBuff, 2, 10, 0, 1, 0
BaseAscii PROC InPut:DWORD, OutPut, Len, Base, Comma, Fill, TermA
LOCAL    LBuff[32]: BYTE

      pushad
         xor     esi, esi
         mov     eax, InPut                ; Input
         mov     ebx, OutPut
         mov     byte ptr [ebx], '0'
      .while (eax)
            xor     edx, edx
            div     Base                   ; Base 10, 16, 8, 2
         .if dl > 9h
               add     dl, 37h             ; Convert to hex ASCII
         .else
               add     dl, 30h             ; Convert to dec ASCII
         .endif
            mov     LBuff[esi], dl
            inc     esi
         .if Comma == 1 && Base == 10 && eax > 0
            .if esi == 3 || esi == 7 || esi == 11
                  mov     LBuff[esi], 2ch  ; Insert commas
                  inc     esi
            .endif
         .endif
      .endw
         xor     edi, edi
         mov     ecx, esi
      .if Len > ecx && Fill == 1           ; Zero fill
            xor     eax, eax
         .while (eax < Len)
               mov     byte ptr [ebx+eax], '0'
               inc     eax
         .endw
            sub     Len, ecx
            add     edi, Len
      .endif
      .while (ecx)
            mov     al, byte ptr LBuff[esi-1]
            mov     byte ptr [ebx+edi], al
            inc     edi
            dec     esi
            dec     ecx
      .endw
      .if TermA
         mov     byte ptr [ebx+edi], 0h
      .endif
       popad
          ret
BaseAscii ENDP
